package com.taotao.cart.service;
import java.io.IOException;

import org.apache.commons.lang3.StringUtils;
import org.apache.http.client.ClientProtocolException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.taotao.cart.bean.Item;
import com.taotao.common.service.ApiService;
import com.taotao.common.service.RedisService;

@Service
public class ItemService {

	@Autowired
	private ApiService apiService;
	@Autowired
	private RedisService redisService;
	@Autowired
	private PropertiesService propertiesService;
	/**
	 * 调用后台系统接口，获取商品信息
	 * @param itemId
	 * @return
	 * @throws IOException 
	 * @throws ClientProtocolException 
	 */
	public Item queryItemById(Long itemId) throws ClientProtocolException, IOException {
		
		//以下是业务代码
		String url = this.propertiesService.TT_MANAGE_URL 
				+ StringUtils.replace(this.propertiesService.ITEM_URL, "{itemid}", itemId.toString());
		
		String jsonItem = this.apiService.doGet(url);
		Item item = null;
		if(StringUtils.isNotEmpty(jsonItem)){
			item = PropertiesService.MAPPER.readValue(jsonItem, Item.class);
		}
		return item;
	}
	

}